package com.guigu.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.CommodityService;
import com.guigu.mapper.CommodityMapper;
import com.guigu.pojo.Commodity;
import com.guigu.pojo.ProductImage;
import com.guigu.pojo.Quote;
import com.guigu.vo.Pojo;
import com.guigu.vo.QuoteVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity> implements CommodityService {
    @Autowired
    private CommodityMapper commodityMapper;
    @Override
    public int selectMaxId() {
        return commodityMapper.selectMaxId();
    }

    @Override
    public int insertImage(ProductImage productImage) {
        return commodityMapper.insertImage(productImage);
    }

    @Override
    public Pojo<Commodity> selectAll(int pageNum, int pageSize) {
       PageHelper.startPage(pageNum,pageSize);
       List<Commodity> commodities = commodityMapper.selectAll(pageNum, pageSize);
       PageInfo<Commodity> commodityPageInfo = new PageInfo<>(commodities);
       Pojo<Commodity> commodityPojo = new Pojo<>();
       commodityPojo.setRows(commodityPageInfo.getList());
       commodityPojo.setTotal(commodityPageInfo.getTotal());
       return commodityPojo;
    }

    @Override
    public Pojo<Quote> selectPrice(int id, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Quote> quotes = commodityMapper.selectPrice(id,pageNum, pageSize);
        PageInfo<Quote> quotePageInfo = new PageInfo<>(quotes);
        Pojo<Quote> quotePojo = new Pojo<>();
        quotePojo.setRows(quotePageInfo.getList());
        quotePojo.setTotal(quotePageInfo.getTotal());
        return quotePojo;
    }
}
